<?php
/**根据关键字查询数据**/
header('Content-Type:application/json');
$output = [];
@$kw = $_REQUEST['kw'];      //搜索关键字
if( empty($kw) ){
    echo '[]';
    return;
}
@$start = $_REQUEST['start'];
if( empty($start) ){ $start = 0;}
$pageSize = 4;  //一次可以向客户端返回的最大的记录数
$conn = mysqli_connect('127.0.0.1','root','','flower');
$sql = 'SET NAMES UTF8';
mysqli_query($conn,$sql);
$sql = "SELECT did,img,name,h_img,type,title,detail FROM fl_dish WHERE name LIKE '%$kw%' OR detail LIKE '%$kw%' LIMIT $start,$pageSize";
$result = mysqli_query($conn, $sql);
while( true ){
    //从结果集中读取一行记录
    $row = mysqli_fetch_assoc($result);
    if(! $row ){  //没有获取到更多记录行
        break;
    }
    $output[] = $row;
}

echo json_encode($output);
?>